package com.wujie.section11;

import java.lang.reflect.Proxy;
import java.security.PublicKey;

/**
 * Created by wujieliu on 2017/10/31.
 */
public class MatchMakingTestDrive {
    public static void main(String[] args) {
        MatchMakingTestDrive test = new MatchMakingTestDrive();
        test.drive();
    }

    public void drive() {
        PersonBean joe = new PersonBeanImpl();
        joe.setName("joe");
        joe.setGender("F");
        joe.setInterests("read book");
        PersonBean ownerProxy = getOwnerProxy(joe);
        System.out.println("Name is : " + ownerProxy.getName());
        ownerProxy.setInterests("bowling ,go");
        System.out.println("Interests set from owner proxy");
        try {
            ownerProxy.setHotOrNotRating(10);
        } catch (Exception e) {
            System.out.println("Can't set rating from   owner proxy");
        }

    }

    public PersonBean getOwnerProxy(PersonBean person) {
        return (PersonBean) Proxy.newProxyInstance(
                person.getClass().getClassLoader(),
                person.getClass().getInterfaces(),
                new OwnerInvocationHandler(person)
        );
    }
}
